package com.zlp.controller;


import com.zlp.dto.req.LoginUserReq;
import com.zlp.dto.req.UserRegisterReq;
import com.zlp.dto.resp.UserLoginResp;
import com.zlp.dto.resp.UserResp;
import com.zlp.service.UserService;
import com.zlp.utils.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 管理用户表 前端控制器
 * </p>
 *
 * @author LiPing.Zou
 * @since 2021-03-12
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user")
@Api(value = "user", tags = "后台用户管理")
public class UserController {

    private final UserService userService;


    @PostMapping("/register")
    @ApiOperation(value = "用户注册")
    public Result<UserResp> register(@Valid @RequestBody UserRegisterReq userRegisterReq) {

        UserResp userResp = userService.register(userRegisterReq);
        return Result.success(userResp);
    }


    @PostMapping("/login")
    @ApiOperation(value = "登录")
    public Result<UserLoginResp> login(@Valid @RequestBody LoginUserReq loginUserReq) {

        return Result.success(userService.login(loginUserReq));
    }

    @GetMapping("/loginOut")
    @ApiOperation(value = "登出")
    public Result<Boolean> loginOut() {

        return Result.success(userService.loginOut());
    }

}

